<script>
export default {
  name: "MView"
}
</script>


<template>
  <h1>EL-员工列表综合练习</h1>
   <el-form style="width: 500px;margin: 0 auto;"label-width="80">
     <el-form-item label="用户名">
       <el-input placeholder="请输入用户名" v-model="user.username"></el-input>
     </el-form-item>
     <el-form-item label="工资">
       <el-input placeholder="请输入工资"  v-model="user.salary"></el-input>
     </el-form-item>
     <el-form-item label="岗位">
       <el-input placeholder="请输入岗位"  v-model="user.job" ></el-input>
     </el-form-item>
      <el-button type="success" @click="show">点击提交</el-button>
   </el-form>
  <el-table :data="arr" style="width: 500px;margin: 0 auto;">
    <el-table-column prop="index" label="编号" align="center" width="80"></el-table-column>
    <el-table-column prop="username" label="用户名" align="center"></el-table-column>
    <el-table-column prop="salary" label="工资" align="center"></el-table-column>
    <el-table-column prop="job" label="岗位" align="center"></el-table-column>
    <el-table-column label="操作">
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>
<script setup>
import {ref} from "vue";
const user = ref({username:"", salary:"", job:"",})

const arr = ref([]);
const show = () => {
  if (!user.value.username || !user.value.username.trim()
      || !user.value.salary || !user.value.salary.trim()
      || !user.value.job || !user.value.job.trim()) {
    alert('请输入完整信息！');
    return;
  }
  arr.value.push(user.value);
  user.value = {};
  console.log(arr.value);
}
const del = (index,user) => {
  if(confirm('确认要删除'+user.username+'吗?')){
    arr.value.splice(index,1);
  }
}
</script>

<style scoped>

</style>